package com.www.bigevent.controller.interceptor;

import com.www.bigevent.pojo.Result;
import com.www.bigevent.utils.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import java.util.Map;

@Component
public class Logininterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //生成token
        String token = request.getHeader("Authorization");
        //验证Token
        try {
            Map<String, Object> claims = JwtUtils.parseToken(token);
            //放行
            return true;
        } catch (Exception e) {
            response.setStatus(401);
            //拦截
            return false;
        }
    }
}
